package com.woniuxy.sys.config;

import com.woniuxy.sys.entity.StoreInfo;
import com.woniuxy.sys.service.IStoreInfoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.CommandLineRunner;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Component;

import java.util.List;

/**
 * 数据预热
 */
@Component
public class InitRunner implements CommandLineRunner{
    @Autowired
    private RedisTemplate redisTemplate;
    @Autowired
    private IStoreInfoService storeInfoService;

    @Override
    public void run(String... args) throws Exception {
        if(!redisTemplate.hasKey("storeList")){
            List<StoreInfo> storeDtos = storeInfoService.list();
            redisTemplate.opsForList().leftPushAll("storeList", storeDtos);
        }
    }
}
